import pymysql
 
# 打开数据库连接
db = pymysql.connect("localhost","root","root","test" )
 
# 使用cursor()方法获取操作游标 
cursor = db.cursor()
 
# SQL 增加语句
sql = """INSERT INTO t_student(id,
         sNumber, sName, cName)
         VALUES ('10', 'Mohan', 20, 'M')"""

try:
   # 执行SQL语句
   cursor.execute(sql)
   db.commit()
except:
   # 如果发生错误则回滚
   db.rollback()
 
# 关闭数据库连接
db.close()